package com.canbot.u05.view

import android.app.Dialog
import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import com.canbot.u05.R
import kotlinx.android.synthetic.main.dialog_dance_detail_edit.view.*
import kotlinx.android.synthetic.main.dialog_dance_detail_edit.view.btn_cancel
import kotlinx.android.synthetic.main.dialog_dance_detail_edit.view.btn_sure
import kotlinx.android.synthetic.main.dialog_dance_tip_both_button.view.*
import kotlinx.android.synthetic.main.dialog_dance_tip_one_button.view.*

/**
 * Created by tao.liu on 2019/7/1.
 * description this is description
 */
class DanceEditDialog(context: Context) {
        private var context: Context

        init {
                this.context = context
        }

        fun editDialog(name: String, onSelect: OnSelectListener): Dialog {
                //创建对话框对象
                //AlertDialog.Builder builder = new AlertDialog.Builder(context);
                val tipDialog = FullScreenDialog(context, R.style.MyDialogStyle)
                //初始化空降
                val view = LayoutInflater.from(context).inflate(R.layout.dialog_dance_detail_edit, null)
                val editName = view.edit_name
                if (!TextUtils.isEmpty(name)) {
                        editName.setText(name)
                }
                val btnCancel = view.btn_cancel
                val btnSure = view.btn_sure
                //定义监听事件
                tipDialog.setContentView(view)
                tipDialog.setCancelable(true)
                btnCancel.setOnClickListener { v ->
                        onSelect.onCancle(v)
                        tipDialog.dismiss()
                }
                btnSure.setOnClickListener { v ->
                        if (!TextUtils.isEmpty(editName.text.toString())) {
                                onSelect.onEnsure(v, editName.text.toString())
                                tipDialog.dismiss()
                        } else {
                                Toast.makeText(context, "输入内容不能为空", Toast.LENGTH_SHORT).show()
                        }

                }
                tipDialog.show()
                return tipDialog
        }

        /**
         * 包含两个按钮的提示框
         */
        fun tipBothButtonDialog(tip: String, onSelect: OnClickedListener): Dialog{
                val tipDialog = FullScreenDialog(context, R.style.MyDialogStyle)
                val view = LayoutInflater.from(context).inflate(R.layout.dialog_dance_tip_both_button, null)
                val btnCancel = view.btn_cancel
                val btnSure = view.btn_sure
                val textView = view.dialog_tip
                textView.text = tip
                //定义监听事件
                tipDialog.setContentView(view)
                tipDialog.setCancelable(true)
                btnCancel.setOnClickListener { v ->
                        onSelect.onCancle(v)
                        tipDialog.dismiss()
                }
                btnSure.setOnClickListener { v ->
                        onSelect.onEnsure(v)
                        tipDialog.dismiss()

                }
                tipDialog.show()
                return tipDialog
        }

        /**
         * 一个button的提示框
         */
        fun tipOneButtonDialog(tip:String,onSelect: OnClickedListener):Dialog{
                val tipDialog = FullScreenDialog(context, R.style.MyDialogStyle)
                val view = LayoutInflater.from(context).inflate(R.layout.dialog_dance_tip_one_button, null)
                val btnSure = view.btn_ok
                val textView = view.dialog_content_tip
                textView.text = tip
                //定义监听事件
                tipDialog.setContentView(view)
                tipDialog.setCancelable(false)
                btnSure.setOnClickListener { v ->
                        tipDialog.dismiss()
                        onSelect.onEnsure(view)

                }
                tipDialog.show()
                return tipDialog
        }
        interface OnClickedListener{
                fun onCancle(view: View)
                fun onEnsure(view: View)
        }
        interface OnSelectListener {

                fun onCancle(view: View)

                fun onEnsure(view: View, newName: String)
        }
}